package dk.RedisUtils;

import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
@Component
public class RedisUtils {
	@Resource
	StringRedisTemplate stringRedisTemplate;
	//存储key value与过期时间
	public void SetKeyAndValueTime(String key,String value,int seconds) {
		stringRedisTemplate.opsForValue().set(key, value,seconds,TimeUnit.SECONDS);
	}
	//得到key value与过期时间
	public Long GetValueTimeByKey(String key) {
		return stringRedisTemplate.getExpire(key);
	}
	//根据key获取值
	public String GetValueByKey(String key) {
		return stringRedisTemplate.opsForValue().get(key);
	}
	//普通的存储key value
	public void SetKeyAndValue(String key,String value) {
		stringRedisTemplate.opsForValue().set(key, value);
	}
	//根据key删除
	public void DeleteValueByKey(String key) {
		stringRedisTemplate.delete(key); 
	}
	//判断key是否存在
	public boolean IsExist(String key) {
		return stringRedisTemplate.hasKey(key);
	}

}
